package main;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;

import model.GameModel;
import model.ModelLockedException;
import model.entities.Direction;
import model.entities.LaserSource;
import model.entities.Mirror;
import model.entities.MirrorOrientation;
import model.entities.Wall;
import model.entities.targets.TransparentTarget;
import view.test.GameBoardPanel;
import view.test.MainFrame;
import view.test.Palette;

public class Main {
	
	public static void main(String[] args) {
		
		init();
			
	}
	
	public static void init() {
	    try {
	        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
	            public void run() {
	                createGUI();
	            }
	        });
	    } catch (Exception e) {
	        System.err.println("createGUI didn't successfully complete");
	    }
	}

	private static void createGUI() {
		
		GameModel model = new GameModel();
		GameBoardPanel panel = new GameBoardPanel(model);
		Palette palette = new Palette();
		MainFrame frame = new MainFrame(panel, palette);
		frame.pack();
		
		frame.add(panel);
		frame.add(palette);
		model.registerWithModel(panel);
		model.createNewGameBoard(new Dimension(10,10));
		
		LaserSource source1 = new LaserSource(Color.RED, Direction.BOTTOM);
		LaserSource source2 = new LaserSource(Color.GREEN, Direction.BOTTOM);
		LaserSource source3 = new LaserSource(Color.GREEN, Direction.BOTTOM);
		LaserSource source4 = new LaserSource(Color.BLUE, Direction.BOTTOM);
		LaserSource source5 = new LaserSource(Color.BLUE, Direction.BOTTOM);
		
		model.getGameBoard().addEntity(source1, new Point(8,7));
		model.getGameBoard().addEntity(source2, new Point(2,7));
		model.getGameBoard().addEntity(source3, new Point(0, 2));
		model.getGameBoard().addEntity(source4, new Point(6, 6));
		model.getGameBoard().addEntity(source5, new Point(1,6));
		
		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.VERTICAL), new Point(0,8));
		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.VERTICAL), new Point(4, 0));
		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.HORIZONTAL), new Point(4, 7));
		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.STEEP_RISE), new Point(4, 8));
		
//		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.NEGATIVE_SLOPE), new Point(3, 1));
//		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.POSITIVE_SLOPE), new Point(1, 1));
//		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.NEGATIVE_SLOPE), new Point(1, 7));
//		model.getGameBoard().addEntity(new Mirror(MirrorOrientation.POSITIVE_SLOPE), new Point(8, 7));
		
		model.getGameBoard().addEntity(new Wall(), new Point(0, 4));
		model.getGameBoard().addEntity(new Wall(), new Point(1, 4));
		model.getGameBoard().addEntity(new Wall(), new Point(1, 5));
		
		model.getGameBoard().addEntity(new Wall(), new Point(3, 2));
		model.getGameBoard().addEntity(new Wall(), new Point(3, 3));
		model.getGameBoard().addEntity(new Wall(), new Point(3, 4));
		model.getGameBoard().addEntity(new Wall(), new Point(3, 5));
		model.getGameBoard().addEntity(new Wall(), new Point(3, 6));
		
		model.getGameBoard().addEntity(new Wall(), new Point(5, 2));
		model.getGameBoard().addEntity(new Wall(), new Point(5, 3));
		model.getGameBoard().addEntity(new Wall(), new Point(5, 4));
		model.getGameBoard().addEntity(new Wall(), new Point(5, 5));
		model.getGameBoard().addEntity(new Wall(), new Point(5, 6));
		
		model.getGameBoard().addEntity(new TransparentTarget(Color.RED), new Point(0,0));
		model.getGameBoard().addEntity(new TransparentTarget(Color.YELLOW), new Point(2, 0));
		model.getGameBoard().addEntity(new TransparentTarget(Color.BLUE), new Point(8, 4));
		model.getGameBoard().addEntity(new TransparentTarget(Color.CYAN), new Point(0,5));
		model.getGameBoard().addEntity(new TransparentTarget(Color.GREEN), new Point(3,7));
		
		try {
			model.setDirty();
		} catch (ModelLockedException e) {
			e.printStackTrace();
		}
	}

	
}
